<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link href="css/BaseCode.css?t=1" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.Drawing.js" type="text/javascript"></script>
    <script src="js/DataBase.js" type="text/javascript" charset="GBK"></script>
    <script src="js/angular.min.js" type="text/javascript"></script>
    <script src="js/Utils.js" type="text/javascript"></script>
    <script src="Angularjs/BaseCtrl.js?t=2" type="text/javascript"></script>
    <script>
        var loadCanvas = function (Cdata,id) {
            $("#"+id).Drawing({
                move: Cdata.move,//初始化坐标值x,y
                data: Cdata.data,
                title: Cdata.title,
                units:Cdata.units,
                offset:Cdata.offset,
                titleFont: Cdata.titleFont
            });
        };
        var loadHtml = function (data, ctrl) {
            var htmls = '<div   class="topDiv"><div class="leftDiv"> <canvas id="'+ctrl+'" width="300px" height="112px"> </canvas></div>';
            htmls += ' <div class="rightDiv"><ul ng-controller="' + ctrl + '">';
            var l = 1;
            for (var i = 0; i < data.length; i++) {
                if (data[i].title == "0") {
                    continue;
                }
                htmls += '  <li><input type="number" class="Code" min="0" ng-model="numbers.number' + l + '"/></li>';
                l++;
            }
            htmls += ' <li>*</li>  <li><input type="number" min="0" ng-model="outher.length"/>mm</li>  <li>=</li>  <li><input style="width:80px" type="text" min="0" ng-model="outher.square"/></li>  <li>m²</li>';
            htmls += '  </ul></div></div>';
            return htmls;
        }
        document.oncontextmenu = function(e){
            if (typeof e.preventDefault === "function") {
                e.preventDefault();
                e.stopPropagation();
            } else {
                e.returnValue = false;
                e.cancelBubble = true;
            }
            $("#itemMenu").css({"left": e.clientX, "top": e.clientY}).fadeIn();
        }
        $(document).bind("click", function (e) {
            var target = $(e.target);
            if (target.closest("#itemMenu").length == 0) {
                $("#itemMenu").hide() ;
            }
        })
        var data=DataUtils.getDataBase(DataUtils.getUrlParam("code"));
        if(data!=null){
            var CodeAngular = new CodeCtrl(data, "BaseCodeApp", DataUtils.getUrlParam("code")+"Ctrl", loadCanvas, loadHtml);
        }
        function fnOk(){
            var obj=$("li");
            $("input").css("border-bottom","0px").css("width","40px");
            $("#itemMenu").hide();
            obj.each(function(i){
                var parentObj=$(this);
                if(parentObj.find("input").hasClass("Code") && i>0)
                {
                    parentObj.prepend("<li>+</li>");
                }
            })
        }
    </script>
</head>

<body  ng-app="BaseCodeApp">
<div ng-controller="CompileCtrl">
    <div compile="html"></div>
</div>
<div id="itemMenu" style="display:none" ng-controller="MenuCtrl">
    <ul>
        <li><a ng-click="Refresh()"  >刷新</a></li>
        <li><a ng-click="Delete()"  >删除</a></li>
        <li><a ng-click="close()" >取消</a></li>
    </ul>
</div>
</body>
</html>
